﻿using Panuon.UI.Silver;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;

namespace psy_service
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        [DllImport("user32", CharSet = CharSet.Unicode)]
        static extern IntPtr FindWindow(string cls, string win);
        [DllImport("user32")]
        static extern IntPtr SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32")]
        static extern bool IsIconic(IntPtr hWnd);
        [DllImport("user32")]
        static extern bool OpenIcon(IntPtr hWnd);
        private static System.Threading.Mutex mutex;
        protected override void OnStartup(StartupEventArgs e)
        {
            mutex = new System.Threading.Mutex(true, "票税云-发票综合服务平台登录服务管理");
            if (mutex.WaitOne(0, false))
            {
                base.OnStartup(e);
                System.Windows.Forms.Application.EnableVisualStyles();
            }
            else
            {
                var other = FindWindow(null, "票税云-发票综合服务平台登录服务管理");
                if (other != IntPtr.Zero)
                {
                    SetForegroundWindow(other);
                    if (IsIconic(other))
                        OpenIcon(other);
                }

                MessageBoxX.Show("请从托盘处启动服务面板","服务面板已经在运行！");
                Shutdown();
            }

        }
    }
}
